#include<stdio.h>
#include<signal.h>
#include<string.h>
#include<unistd.h>
#include<errno.h>
#include<sys/types.h>
#include<sys/wait.h>

void sig_int(int signo)
{
     printf(" %d is caught: interrupt\n",signo);

     exit(0);
}


int main(int argc,char **argv)
{
     char        buf[10];
     pid_t       pid = -1;
     int         status;

     if(signal(SIGINT,sig_int) == SIG_ERR)
         printf("SIG_ERR: signal error");

     printf("%%");
     while(fgets(buf,sizeof(buf),stdin) != NULL)
     {
         if(buf[strlen(buf) - 1] == '\n')
             buf[strlen(buf) - 1] = 0;

         if((pid = fork()) < 0)
             printf("fork failure: %s\n",strerror(errno));

         else if((pid = fork()) == 0)
             execlp(buf,buf,(char *)0);

         if((pid = waitpid(pid,&status,0)) < 0)
             printf("wait failure: %s\n",strerror(errno));
 
         printf("%%");
     }

      return 0;
}
